package com.ruoyi.internet.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.internet.domain.IntEntrust;
import com.ruoyi.internet.service.IIntEntrustService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 委托办理Controller
 *
 * @author cjie
 * @date 2021-08-16
 */
@Api(tags = " 委托办理")
@RestController
@RequestMapping("/intEntrust")
public class IntEntrustController extends BaseController {
    @Autowired
    private IIntEntrustService intEntrustService;

    /**
     * 查询委托办理列表
     */
    @ApiOperation(value="查询委托办理列表", notes="查询委托办理列表")
    @GetMapping("/list")
    public TableDataInfo list(IntEntrust intEntrust) {
        startPage();
        List<IntEntrust> list = intEntrustService.selectIntEntrustList(intEntrust);
        return getDataTable(list);
    }

    /**
     * 导出委托办理列表
     */
    @ApiOperation(value="导出委托办理列表", notes="导出委托办理列表")
    @Log(title = "委托办理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntEntrust intEntrust) throws IOException {
        List<IntEntrust> list = intEntrustService.selectIntEntrustList(intEntrust);
        ExcelUtil<IntEntrust> util = new ExcelUtil<IntEntrust>(IntEntrust.class);
        util.exportExcel(response, list, "委托办理数据");
    }
    /**
     * 获取委托办理详细信息
     */
    @ApiOperation(value="获取委托办理详细信息", notes="获取委托办理详细信息")
    @GetMapping(value = "/info/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(intEntrustService.selectIntEntrustById(id));
    }

    /**
     * 新增委托办理
     */
    @ApiOperation(value="新增委托办理", notes="新增委托办理")
    @PreAuthorize(hasPublish = "Y")
    @Log(title = "委托办理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntEntrust intEntrust) {
        return toAjax(intEntrustService.insertIntEntrust(intEntrust));
    }

    /**
     * 修改委托办理
     */
    @ApiOperation(value="修改委托办理", notes="修改委托办理")
    @PreAuthorize(hasPublish = "Y")
    @Log(title = "委托办理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntEntrust intEntrust) {
        return toAjax(intEntrustService.updateIntEntrust(intEntrust));
    }

    /**
     * 删除委托办理
     */
    @ApiOperation(value="删除委托办理", notes="删除委托办理")
    @ApiImplicitParam(name = "ids", value = "委托办理ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPublish = "Y")
    @Log(title = "委托办理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(intEntrustService.deleteIntEntrustByIds(ids));
    }
}
